package info.ask4research.model.activities;

import info.ask4research.model.FileUploadBean;
import info.ask4research.model.UnitOfLearning;
import info.ask4research.model.User;
import info.ask4research.model.addons.Addon;
import info.ask4research.model.enums.FinishingActivity;
import info.ask4research.model.roles.Role;
import info.ask4research.model.toolsAndMaterials.ToolAndMaterial;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonProperty;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
@Table(name = "ACTIVITY")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "DISCRIMINATOR", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("TYPE")
@JsonAutoDetect
public class Activity {

	
	@Id
	@GeneratedValue
	@Column(name="activity_ID")
	private int id;
	@Column(name="activityGraphID")
	private String activityGraphId;
	@Column(name="description", nullable=true)
	@Lob
	@JsonProperty
	private String description;
	@Column(name="visible", nullable=true)
	private boolean visible;
	@OneToOne
	@JoinColumn(name="Author_id", unique=false, nullable=true, updatable=true)
	private Role author;
	@Enumerated(EnumType.STRING)
	@Column(name="finishingActivity")
	private FinishingActivity finishingActivity; 
	@Column(name="timeLimit", nullable=true)
	private String timeLimit;
	@ManyToOne
	@LazyCollection(LazyCollectionOption.FALSE)
	private UnitOfLearning unitOfLearning;

	@LazyCollection(LazyCollectionOption.FALSE)
	@ManyToMany
    @JoinTable(name="ACTIVITY_ADDONS",  joinColumns= @JoinColumn(name="ADDON_ID", referencedColumnName="activity_ID"))
	private List<Addon> addons = new ArrayList<Addon>();
	@LazyCollection(LazyCollectionOption.FALSE)
	@ManyToMany
    @JoinTable(name="ACTIVITY_TAMS",  joinColumns= @JoinColumn(name="TAM_ID", referencedColumnName="activity_ID"))
	private List<ToolAndMaterial> tams = new ArrayList<ToolAndMaterial>();
	@ManyToMany
	@LazyCollection(LazyCollectionOption.FALSE)
	@JoinTable(name = "ResourcesActivities", joinColumns =@JoinColumn(name="file_ID", referencedColumnName="activity_ID"))
	private List<FileUploadBean> files = new ArrayList<FileUploadBean>();
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public List<Addon> getAddons() {
		return addons;
	}
	public void setAddons(List<Addon> addons) {
		this.addons = addons;
	}
	public List<ToolAndMaterial> getTams() {
		return tams;
	}
	public void setTams(List<ToolAndMaterial> tams) {
		this.tams = tams;
	}
	public boolean isVisible() {
		return visible;
	}
	public void setVisible(boolean visible) {
		this.visible = visible;
	}
	public FinishingActivity getFinishingActivity() {
		return finishingActivity;
	}
	public void setFinishingActivity(FinishingActivity finishingActivity) {
		this.finishingActivity = finishingActivity;
	}
	public String getTimeLimit() {
		return timeLimit;
	}
	public void setTimeLimit(String timeLimit) {
		this.timeLimit = timeLimit;
	}
	public List<FileUploadBean> getFiles() {
		return files;
	}
	public void setFiles(List<FileUploadBean> files) {
		this.files = files;
	}
	public void addFiles(FileUploadBean file) {
		this.files.add(file);
	}
	public void removeFiles(FileUploadBean file) {
		this.files.remove(file);
	}
	public String getActivityGraphId() {
		return activityGraphId;
	}
	public void setActivityGraphId(String activityGraphId) {
		this.activityGraphId = activityGraphId;
	}
	public Role getAuthor() {
		return author;
	}
	public void setAuthor(Role author) {
		this.author = author;
	}
	public UnitOfLearning getUnitOfLearning() {
		return unitOfLearning;
	}
	public void setUnitOfLearning(UnitOfLearning unitOfLearning) {
		this.unitOfLearning = unitOfLearning;
	}
}
